﻿@*YoursLC有源低代码 Create:φ创建者Creatorφ 2022-05-07 19:30:18 添加或编辑-此文件放置于Views/Data01/中*@

@using Think9.Models;
@model Think9.Models.Data01Model
@{ ViewBag.Title = "Add";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

@*data01经济分类*@

<form class="layui-form" lay-filter="formUser">
<input style="display:none" id="_userid" value="@ViewBag.UserId">@*用户id*@
<input style="display:none" id="_attachmentId">@*附件id*@
<input style="display:none" id="_type" value="@ViewBag.Type">@*add或edit*@
<input style="display:none" id="prc_fid" value="@ViewBag.FId">@*当前流程编码*@
<input style="display:none" id="prc_id"  value="@ViewBag.PrcId">@*当前流程步骤id*@
<input style="display:none" id="prc_no"  value="@ViewBag.PrcNo">@*当前流程步骤编码*@
<input style="display:none" id="sys_plit" value="@ViewBag.Split">@*多选框字符分割*@
<input style="display:none" id="sys_listid" value="@ViewBag.ListId">
<input style="display:none" id="Pu_value">
<input style="display:none" id="Pu_tbid">
<input style="display:none" id="Pu_indexid">
<input style="display:none" id="Pu_id">
<input style="display:none" id="Pu_v">
<div class="layui-form">
 <div class="layui-form-item"  style="text-align: right;">
	<div class="layui-btn-group">
			@*<button type="button" class="layui-btn" id="sys_att">附件</button>*@
			<button type="button" class="layui-btn" lay-submit lay-filter="edit">保存</button>
			@*<button type="button" class="layui-btn" lay-submit lay-filter="next">转交</button>*@
			@*<button type="button" class="layui-btn" lay-submit lay-filter="finish">结束</button>*@
	 </div>
  </div>

	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label required">编码</label>
			<div class="layui-input-block">
				<input type='text' name='inCode' id='inCode' autocomplete='off' class='layui-input'  maxlength='30'    lay-verify='required'  placeholder='编码'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
				<input type='text' name='inName' id='inName' autocomplete='off' class='layui-input'  maxlength='100'    placeholder='名称'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type='text' name='inRemarks' id='inRemarks' autocomplete='off' class='layui-input'  maxlength='200'    placeholder='备注'>
				</div>
			</div>
	 </div>
</div>

</form>
<script>
	layui.config({
		base: '/self_js/'  /*自定义的js文件 位于wwwroot/self_js文件夹中*/
	});
	layui.use(["form", "exLayer", "exUtils",  "table", "Data01"], function () {
		let form = layui.form;
		let layer = layui.layer;
		let table = layui.table;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let mySelf = layui.Data01;

		let $ = layui.$;
		form.render();

		getFormVal();//设置多选框和图片的显示--无多选框和图片可删除
		lockForEditing();//编辑时锁定
		//根据步骤编码设置控件disabled
		mySelf.setStateByFlow($('#prc_no').val());
		//赋值--不包括多选框和图片
		form.val("formUser", {
			"inCode": "@Model.inCode"
			,"inName": "@Model.inName"
			,"inRemarks": "@Model.inRemarks"
		});
		//设置多选框和图片的显示
		function getFormVal() {


		}
		//编辑时锁定
		function lockForEditing() {
			if ($('#_type').val() == 'edit') {
				$('#inCode').attr('disabled','disabled');//编码
			}
		}



		//点击保存按钮
		form.on("submit(edit)", function (data) {
			var _gridList = [];
			mySelf.foreachGridTable(_gridList);//遍历子表table取数
			exUtils.ajax('/Data01/SaveData', 'post', {
				model: data.field, 'gridlist': _gridList, listid: $('#sys_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val() }, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
				$(window.parent.document).find('#search').click();
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			});
		}).fail(function (error) {
			console.log(error);
		});
			return false;
		});




		//弹出页面关闭后为控件赋值 无弹出页面可删除
		$("#Pu_value").click(function () {
			mySelf.getValueFromPopUp();//控件赋值
			readValue();//执行数据读取
		});

		//数据读取
		function readValue() {
			var _gridList = [];
			mySelf.getSelectGridTable(_gridList, $('#Pu_tbid').val(), $('#Pu_id').val());

			var _controlsList = [];
			$.each($("form").serializeArray(), function (i, field) {
				_controlsList.push({ ControlID: field.name, ControlValue: field.value });
			  /*  alert(field.name + ":" + field.value);*/
			});
			//还要将禁用的控件push

			exUtils.ajax("/Data01/AfterControlSelect", "post", { controlslist: _controlsList, "gridlist": _gridList, id: $('#Pu_id').val(), tbid: $('#Pu_tbid').val(), indexid: $('#Pu_indexid').val(), value: $('#Pu_value').val() }, true).done(function (response) {
				lists = response.list;
				console.log(lists);
				//使用后台返回的lists，为控件赋值
				mySelf.setValueByList(lists);

				form.render();//一定要加
			}).fail(function (error) {
				console.log(error);
			});

			return false;
		}

	});
</script>